package com.lanyuan.util;

import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

public class CommonUtil {

    private static String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static String generateCode() {
        int a = ThreadLocalRandom.current().nextInt(24);
        int b = a + 3;
        return ALPHABET.substring(a, b) + Sha1Util.getTimeStamp();
    }

    public static <T> T getFirstOrNull(List<T> list) {
        return list == null || list.isEmpty() ? null : list.get(0);
    }

    public static void main(String[] args) {
        System.out.println(CommonUtil.generateCode());
    }

    /**
     * 扣除8%的税，截流
     */
    public static BigDecimal calcNetincome(BigDecimal rawIncome) {
        return rawIncome.multiply(new BigDecimal("0.92")).setScale(2, BigDecimal.ROUND_FLOOR);
    }

    public static int parseInt(String str) {
        int result = 0;
        if (StringUtils.isEmpty(str)) {
            return result;
        }
        try {
            result = Integer.parseInt(str);
        } catch (Exception e) {
        }
        return result;
    }

}
